import {defineStore} from "pinia";
import {ref} from "vue";
import {NAMESPACE_MENU} from "../interface/menu.ts";
import {queryMenu} from "../api/menu.ts";
import {formatToTree} from "../util/common.ts";

//第一个参数是唯一storeId
export const useMenuStore = defineStore("useMenuStore",()=>{
    const menus = ref<Array<NAMESPACE_MENU.MenuItem>>()
    const getMenuList = ()=>{
        queryMenu({
            pageNo:1,
            pageSize:10000
        }).then(data => menus.value = formatToTree(data.data, 0))
    }
    return {
        menus,
        getMenuList
    }
})
